//日期格式化yyyy-MM-dd hh:mm:ss
/* 
 * @param {Date} date 要格式化的日期时间对象
 * @param {Number} type 格式化类型，1：yyyy-MM-dd hh:mm:ss，2：yyyy-MM-dd，3：hh:mm:ss，4：yyyy-MM-dd hh:mm，5：MM-dd hh:mm，默认为1
 * @return {String} 格式化后的日期时间字符串
 */
const getDateStr = (type = 4, date = new Date()) => {
	let year = date.getFullYear();
	let month = (date.getMonth() + 1).toString().padStart(2, '0');
	let day = date.getDate().toString().padStart(2, '0');
	let hour = date.getHours();
	let minute = date.getMinutes()
	let second = date.getSeconds().toString().padStart(2, '0');
	if (type === 1) {
		return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
	} else if (type === 2) {
		return `${year}-${month}-${day}`;
	} else if (type === 4) {
		return `${year}-${month}-${day} ${hour}:${minute}`
	} else if (type === 5) {
		return `${month}-${day} ${hour}:${minute}`
	} else {
		return `${hour}:${minute}:${second}`
	}

}
export default getDateStr;